import {Component, OnInit} from '@angular/core';
import {FormGroup} from '@angular/forms';

import {
  CustomizeFormValidateService,
  ICustomizeFormValidate
} from '../../../sources/service/customize-form-validate.service';

@Component({
  selector: 'app-register',
  templateUrl: './register.component.html',
  styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit, ICustomizeFormValidate {
  formName: string;
  formGroup: FormGroup;
  formModel: any;
  formErrors: { [p: string]: string };
  formPlaceholder: { [p: string]: string };
  validationMessages: { [p: string]: { [p: string]: string } };

  constructor(private formService: CustomizeFormValidateService) {
  }

  ngOnInit() {
    this.formName = 'register';
    this.formModel = {'userName': '', 'userPass': '', 'userRePass': '', 'birthday': '', 'email': '', 'mobile': ''};
    this.formService.buildForm(this);
  }

  onFormSubmit() {
    if (this.formGroup.valid) {
      console.log('表单验证通过，提交信息')
    } else {
      console.log('表单验证不通过，禁止提交信息');
    }
  }
}
